<template>
    <el-dialog
            :close-on-click-modal="false"
            :show-close="false"
            :title="form.type == 5 ? '扣除':'推送'"
            :visible.sync="isEdit"
    >
        <el-form
                :rules="rules"
                ref="ruleForm"
                :model="form"
                label-width="120px"
                size="small"
                class="form-box"
        >
            <el-form-item v-if="form.type == 5" label="扣除金额" prop="amount">
                <el-input type="number" v-model="form.amount" placeholder="请输入扣除金额"></el-input>
            </el-form-item>
            <el-form-item v-else label="推送金额" prop="amount">
                <el-input type="number" v-model="form.amount" placeholder="请输入推送金额"></el-input>
            </el-form-item>
            <el-form-item label="备注">
                <el-input type="textarea" v-model="form.remark" placeholder=""></el-input>
            </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
      <el-button @click="$emit('closeDialog')" size="small">取消</el-button>
      <el-button @click="submitFormAdd('ruleForm')" type="primary" size="small">确定</el-button>
    </span>
    </el-dialog>
</template>

<script lang="ts">
    import {Component, Vue, Prop, Provide} from "vue-property-decorator";
    import staffManag from "@/api/staffManag";

    @Component({
        components: {}
    })
    export default class typeEditDialog extends Vue {
        // 属性或参数中使用 ！：表示强制解析（告诉typescript编译器，这里一定有值），常用于vue-decorator中的@Prop
        check: boolean = true//防重复提交
        @Prop(Number) id!: number
        @Prop(Boolean) isEdit!: boolean;
        @Prop(Boolean) isAdd!: boolean;
        @Prop(Array) projectNames!: [];
        @Provide() dateTime: any = [];
        @Prop(Object) form!: {
            id: string,
            type: string,
            amount: string,
            remark: string,
        };
        @Provide() rules: any = {
            amount: [{required: true, message: "请输入金额", trigger: "blur"}, {
                //pattern: /^[1-9]\d*(\.\d+)?$/,  //大于1
                pattern: /^(?!(0[0-9]{0,}$))[0-9]{1,}[.]{0,}[0-9]{0,}$/,  //正则
                message: '请输入大于0的数'
            }],
        };

        // 提交
        submitFormAdd(formName: any) {
            (this.$refs[formName] as any).validate((valid: boolean) => {
                if (valid) {
                    if (this.check) {
                        let _this = this
                        _this.check = false
                        staffManag.employeeAmount(_this.form)
                            .then((res: any) => {
                                if (res.data.code == 200) {
                                    _this.$message({
                                        message: res.data.msg,
                                        type: "success"
                                    });
                                    _this.$emit("closeDialog");
                                    _this.$emit("loadData")
                                    setTimeout(function () {
                                        _this.check = true
                                    }, 3000)
                                } else {
                                    _this.$message({
                                        message: res.data.msg,
                                        type: "error"
                                    });
                                    _this.check = true
                                }
                            });
                    }
                }
            })
        }

        created() {
        }
    }
</script>

<style lang="scss" scoped>
    .form-box {
        .el-input,
        .el-select {
            width: 200px !important;
        }
    }
</style>
